/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var questionAdd = {
    MaxSelectionSize: 2,
    selectionSize: 0,
    selection0A: '<tr><td class="tr"><label class="initStart">*</label>'
    + "第",
    selection0B: "个选项" + '：</td>'
    + '<td class="tl"> <textarea  rows="2" cols="20" style="width:400px;" '
    + 'class="com-textarea" name="selection" datatype="*1-100" '
    + 'errormsg="字数最多100个！" nullmsg="选项不能为空！" ></textarea></td>'
    + '<td style="width: 150px;"><div class="Validform_checktip">'
    + '<td class="tr"><label class="initStart">*</label>分值</td>'
    + '<td class="tl"><input type="text" style="width:100px;"'
    + 'class="com-inp fr-text" name="selectionVal" datatype="*1-3"'
    + 'errormsg="字数最多3个！" nullmsg="分值不能为空！" />分</td>'
    + '<td style="width: 30px;"><div class="Validform_checktip"></tr>',
    //  showQuestion:function(){
    //var tr = null;
    /*
     for(questionAdd.selectionSize; questionAdd.selectionSize < questionAdd.MaxSelectionSize; ){
     questionAdd.selectionSize = questionAdd.selectionSize + 1;
     tr += questionAdd.selection0A + questionAdd.selectionSize  + questionAdd.selection0B;
     }
     $('tbody').html(tr);
     */
    startEvent: function () {
        comValidform = $(".com-addForm").Validform({
            datatype: {
                "m0-2": /^[0-9]+(.[0-9]{1,2})?$/
            },
            tiptype: 2,
            tipSweep: true,

            beforeSubmit: function (curform) {
                var url = 'mgr/questionCtrl/save';

                var question = $.trim($("#question").val());

                var answer = null;

                var value = null;

                $('input[name="nw"]')
                var selection1 = $("#selection1").val();
                var selection2 = $("#selection2").val();
                var selection3 = $("#selection3").val();
                var selection4 = $("#selection4").val();
                var selection5 = $("#selection5").val();
                var selection6 = $("#selection6").val();
                var selectionVal1 = $("#selectionVal1").val();
                var selectionVal2 = $("#selectionVal2").val();
                var selectionVal3 = $("#selectionVal3").val();
                var selectionVal4 = $("#selectionVal4").val();
                var selectionVal5 = $("#selectionVal5").val();
                var selectionVal6 = $("#selectionVal6").val();


                var seqNum = $("#seqNum").val();
                var groupId = $("#groupId").val();


                answer = $.trim(selection1) + ","
                    + $.trim(selection2) + ","
                    + $.trim(selection3);

                value = $.trim(selectionVal1) + ","
                    + $.trim(selectionVal2) + ","
                    + $.trim(selectionVal3);

                if ($.trim(selection4) != 0) {
                    answer += "," + $.trim(selection4);
                    value += "," + $.trim(selectionVal4);
                }

                if ($.trim(selection5) != 0) {
                    answer += "," + $.trim(selection5);
                    value += "," + $.trim(selectionVal5);
                }

                if ($.trim(selection6) != 0) {
                    answer += "," + $.trim(selection6);
                    value += "," + $.trim(selectionVal6);
                }

                var params = {
                    "questionArray": question,
                    "selectionArray": answer,
                    "selectionValArray": value,
                    "seqNum": seqNum,
                    "groupId": groupId,
                    "userId":userId
                };
                var cb = function (data) {
                    //成功返回
                    if (data.resultCode == 200) {
                        //关闭窗口并刷新数据
                        art.dialog.close();
                        returnStatus = true;
                    }
                    else
                        alert(data.msg);
                };
                sendApiNoLoadSync(url, params, cb, 'POST');
                return false;
            }
        });
    },

    init: function () {
        questionAdd.startEvent();
    }
}
$(document).ready(function () {
    questionAdd.init();
});
function submitForm() {
    comValidform.submitForm();
    return returnStatus;
}